package org.ntu.rtsearch.store;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * @author fuhao(email: hfhimage@gmail.com)         
 * @date 2011-7-22
 */
public class FSInputStream extends InputStream {

	private RandomAccessFile file;
	
	private boolean isOpen;
	
	public FSInputStream(String path) throws IOException {
		file = new RandomAccessFile(path, "rw");
		lenght = file.length();
		isOpen = true;
	}
	
	@Override
	protected void seekInternal(long pos) throws IOException {
		file.seek(pos);
	}

	@Override
	protected void readInternal(byte[] b, int offset, int len) throws IOException {
		long position = getFilePointer();
		if(position != file.getFilePointer()) {
			
		}
		file.read(b, offset, len);
	}

	@Override
	public void close() throws IOException {
		if(isOpen) {
			file.close();
			isOpen = false;
		}
	}
	
	public final void finalize() throws IOException {
		if(isOpen) {
			file.close();
			isOpen = false;
		}
	}

}
